package com.cnxdc.demo.controller;

import com.cnxdc.demo.service.ArticleService;
import com.cnxdc.demo.vo.Article;
import com.cnxdc.demo.vo.PageBean;
import com.cnxdc.demo.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping
    public Result add(@RequestBody @Validated Article article) {
        articleService.add(article);
        return Result.success();
    }

    @GetMapping
    public Result<PageBean<Article>> get(Integer pageNum,Integer pageSize,Integer categoryId,String state) {
        PageBean<Article> list = articleService.list(pageNum, pageSize, categoryId, state);
        return Result.success(list);
    }
}
